<?php $this->load->view("common/header"); ?>

<script type="text/javascript">
$(function(){
			$('#test').datagrid({
				title:'<?php echo $this->lang->line("user_management_system"); ?>',
				iconCls:'icon-save',
				width:'80%',
				height:'400',
				method:'post',
				nowrap: false,
				striped: true,
				collapsible:true,
				url:'<?php echo base_url(); ?>index.php/user/user/datagrid',
				sortName: 'ID',
				sortOrder: 'asc',
				remoteSort: true,
				fitColumns:true,
				idField:'id',
				
				frozenColumns:[[
	                {field:'ck',checkbox:true},
	                {title:'ID',field:'id',width:80,sortable:true}
				]],
				columns:[[
			        {title:'<?php echo $this->lang->line("basic_information"); ?>',colspan:5},
					{field:'opt',title:'<?php echo $this->lang->line("action"); ?>',width:100,align:'center', rowspan:2,
						formatter:function(value,rec){
							return '<span style="color:red"><a href="#" onclick="javascript:clickEdit('+rec.id+');" ><?php echo $this->lang->line("edit"); ?></a> <a href="#" onclick="javascript:clickDelete('+rec.id+');" ><?php echo $this->lang->line("delete"); ?></a></span>';
						}
					}
				],[
					{field:'username',title:'<?php echo $this->lang->line("system_username"); ?>',width:120,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					
					{field:'lastname',title:'<?php echo $this->lang->line("system_user_lastname"); ?>',width:120,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'firstname',title:'<?php echo $this->lang->line("system_user_firstname"); ?>',width:120,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'email',title:'Email',width:120,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'comments',title:'<?php echo $this->lang->line("comments"); ?>',width:220}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'btnadd',
					text:'<?php echo $this->lang->line("add_system_user"); ?>',
					iconCls:'icon-add',
					handler:function(){
						$('#add_record').load('<?php echo site_url("user/user/add/"); ?>').window({modal:true}); 
					}
				},
				{
					id:'btnadd',
					text:'<?php echo $this->lang->line("search"); ?>',
					iconCls:'icon-add',
					handler:function(){
						$('#search_window').window({modal:true}); 
						
					}
				}]
			});
			
			var p = $('#test').datagrid('getPager');
			if (p){
				$(p).pagination({
					onBeforeRefresh:function(){
						alert('before refresh');
					}
				});
			}
			


		
		});
		
		/*如果点击检索按钮*/
		function clickSearch(){
		
			var key = $("#keywords").val();
			
	
			$('#test').datagrid('options').queryParams={key:key};
			$('#search_window').window("close");
			$('#test').datagrid('reload');

		}
		/*检索结束*/
		
		/*打开编辑窗口*/
		function clickEdit(mid)
		{
			
			$('#edit_record').load('<?php echo site_url("user/user/edit/'+mid+'"); ?>').window({modal:true}); 
			
		}
		/*打开编辑窗口结束*/
		
		function clickDelete(mid)
		{
					var data = 'user_id='+mid;
					
					$.ajax({
						type:"POST",
						url:'<?php echo site_url("user/user/delete"); ?>',
						data: data,
						success : function(data) {
							if (data == "succ") {
								$.messager.alert('<?php echo $this->lang->line("system_prompt"); ?>', '<?php echo $this->lang->line("deleted_success"); ?>！', 'info');
								
								$('#test').datagrid('reload');
							} else {
								$.messager.alert('<?php echo $this->lang->line("system_prompt"); ?>', data, 'error');
							}
						}
					});
					
		}
		
		
		
		
</script>



<table id="test">

</table>

<div id="add_record" title="<?php echo $this->lang->line("add_record"); ?>" style="padding:5px;width:700px;height:400px;">



</div>

<div id="edit_record" title="<?php echo $this->lang->line("edit_record"); ?>" style="padding:5px;width:700px;height:400px;">

</div>

<div id="search_window" title="<?php echo $this->lang->line("search_window"); ?>" style="padding:5px;width:500px;height:300px;">
	
    
        <div style="padding:10px;">
            <form name="searchform" id="searchform" action="" method="post">
                <fieldset>
                <legend><?php echo $this->lang->line("common_search_title"); ?></legend>
    
            Keyword: <input name="keywords" id="keywords" value="" class="easyui-validatebox" style="width:180px">
           
            
            <a href="#" class="easyui-linkbutton"  onclick="javascript:clickSearch();"><?php echo $this->lang->line('common_search'); ?></a>
                </fieldset>
            </form>
        </div>
	
</div>



<?php $this->load->view("common/footer"); ?>